package com.gxc.utils;

import java.io.Serializable;

/**
 * @author GongXincheng
 * @since 2019-08-08 14:49
 */
public class RestControllerResult<T> implements Serializable {

    private boolean success;
    private T data;
    private String message;

    public RestControllerResult() {
    }

    public RestControllerResult(boolean success, T data) {
        this.success = success;
        this.data = data;
    }

    public RestControllerResult(boolean success, T data, String message) {
        this.success = success;
        this.data = data;
        this.message = message;
    }

    public static <T> RestControllerResult<T> success(T data) {
        RestControllerResult<T> result = new RestControllerResult<>();
        result.setSuccess(true);
        result.setData(data);
        return result;
    }

    public static <T> RestControllerResult<T> error(String message) {
        RestControllerResult<T> result = new RestControllerResult<>();
        result.setSuccess(false);
        result.setMessage(message);
        return result;
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }
}
